package com.zxy.leetcode._00500_00599._00500_00509;

/**
 * 七进制数
 */
public class Test00504 {

    public static void main(String[] args) {
        Test00504 test = new Test00504();
        System.out.println(test.convertToBase7(100));
        System.out.println(test.convertToBase7(-7));
    }

    public String convertToBase7(int num) {
        if (num == 0) {
            return "0";
        }

        StringBuilder stringBuilder = new StringBuilder();
        boolean flag = (num < 0);
        if (flag) {
            num = -num;
        }

        while (num != 0) {
            stringBuilder.insert(0, num % 7);
            num /= 7;
        }
        if (flag) {
            stringBuilder.insert(0, "-");
        }

        return stringBuilder.toString();
    }
}
